<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>H5素材列表</title>
    <link rel="shortcut icon" href="favicon.ico"> 
    <link href="<%=path%>/hplus/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="<%=path%>/hplus/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/footable/footable.core.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/plugins/dataTables/css/jquery.dataTables.min.css"/>
    <link href="<%=path%>/hplus/css/animate.min.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/style.min862f.css?v=4.1.0" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="<%=path%>/hplus/js/plugins/sweetalert/sweetalert2.min.css">
    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <style> 
        .col-sm-1{
            font-weight: normal;
        } 
       
        
        .caoZuo{font-size: 15px;margin: 0 4px;color:#676a6c}
        table.dataTable tbody th, table.dataTable tbody td{
        padding:0;
        }
        
        /* table.dataTable tbody th{
            padding-left:10;
            padding-top:5;
            padding-bottom:5;
        
        } */
        
        table.dataTable tbody td{
            padding-left:10;
        }  
        .ellipsis {
            overflow: hidden; /*自动隐藏文字*/
            text-overflow: ellipsis;/*文字隐藏后添加省略号*/
            white-space: nowrap;/*强制不换行*/
            width: 16em;/*不允许出现半汉字截断*/
        }
    </style>
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content">
        <div class="col-md-12 ibox-content">
<!--             <div class="col-md-12">
               <h3 class="col-md-1" style="margin-left:-15px">H5素材</h3>
               
                  <h5 style="margin-top:7px;color:#999">H5素材是酷客域名下的H5页面，支持生成长图文、插入跳转链接、表单提交、派发优惠券。使用场景丰富，可用于传播统计、营销活动、微信扫描二维码回复、自定义菜单、自动回复、分享等。</h5>
            </div> -->
            <div class="col-md-12" style="margin-top:15px;margin-bottom: 15px;color:#1ab394">
                        </div>
            <form class="form-horizontal col-md-12">
              <div class="col-sm-3 text-left" style="margin-left:-15px">
                  <label class="col-sm-4 control-label" style="text-align: left;">H5页面名称</label>
                  <div class="col-sm-8" style="margin-left:-30px">
                      <input id="materialName" type="text" class="form-control" placeholder="请输入H5页面名称"  maxlength="20" onblur="checkLength(this)">
                  </div>
              </div> 
              <div class="col-sm-4" style="margin-left:-70px">
                  <label class="col-sm-4 control-label">创建者</label>
                  <div class="col-sm-8" style="margin-left:-15px">
                      <input id="createUser" type="text" class="form-control" placeholder="请输入创建者名称" maxlength="20" onblur="checkLength(this)">
                  </div>
              </div> 
              <div class="col-sm-1" style="margin-left:-20px;padding-right:0px">
                  <button onclick="javascript:search();" class="btn btn-primary full-right" type="button">搜索</button>
              </div>
              <div class="col-md-4 pull-right text-right">
                   <shiro:hasPermission name="aem_material_list:batch_delete">
                     <button onclick="javascript:deleteByBatch();" class="btn btn-primary" type="button" style="margin-right:5px">批量删除</button>
                   </shiro:hasPermission>
                   <shiro:hasPermission name="aem_material_list:create_pic">
                     <button type="button" class="btn btn-primary" onclick="window.location.href='<%=path%>/material/teletextMaterialCreate?handleType=create'" style="margin-right:5px">创建H5图文</button>
                   </shiro:hasPermission>
                   
                   <shiro:hasPermission name="aem_material_list:create_album">
                     <button type="button" class="btn btn-primary" onclick="window.location.href='<%=path%>/material/photoAlbumMaterialCreate?handleType=create'" style="margin-right:5px">创建H5相册</button>
                   </shiro:hasPermission>
             </div>
            </form> 
            
             <div class="col-sm-12" style="margin-top:20px;">
                <div class="ibox float-e-margins">
                    <div class="table-responsive">
                        <table class="table-striped table-bordered table-hover dataTable no-footer" id="mydataTable">
                            <thead>
                                <tr style="font-size:14px;font-weight: bold;padding-top:0px;padding-bottom: 0px">
                                   
                                   <td style="padding-top:0px;padding-bottom: 0px">
                                      <div style="font-weight:bold;" class="checkbox i-checks"><label class="select_all"><input  type="checkbox" ></label>序号</div>
                                   </td>
                                   <th style="padding-top:0px;padding-bottom: 0px">H5页面名称</th>
<!--                                    <th style="padding-top:0px;padding-bottom: 0px">UV/PV</th>
                                   <th style="padding-top:0px;padding-bottom: 0px">分享人数</th>
                                   <th style="padding-top:0px;padding-bottom: 0px">提表人数</th> -->
                                   <th style="padding-top:0px;padding-bottom: 0px">状态</th>
                                   <th style="padding-top:0px;padding-bottom: 0px">有效期</th>
                                   <th style="padding-top:0px;padding-bottom: 0px">操作</th>
                                </tr>
                            </thead>
                            <tbody style="font-size:14px">
                            </tbody>
                        </table>
                    </div>                 
                </div>
            </div>
        </div>      
    </div>
    
    <div class="modal inmodal" id="customMadeMaterial" tabindex="-1" role="dialog"  aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content animated fadeIn">
               <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title">定制素材</h4>
                </div> 
                <div class="modal-body col-md-12">
                    <p style="color:#1ab394">zhfeat运营团队拥有丰富的客户运营经验，致力于帮助企业解决客户运营问题，可提供从H5活动策划、定制开发到H5推广宣传运营全案服务。如果您的企业需要此类服务，请留下联系方式，我们的运营人员会与您取得联系。</p>
                    <div class="text-center" style="width:100%;">                    
	                    <form method="get" class="form-horizontal col-sm-12" style="margin-top:30px;">
	                        <div class="form-group" >
			                     <label class="col-sm-4 control-label">姓名</label>
			                     <div class="col-sm-6">
			                        <input id="name" type="text" class="form-control shareTitle"  maxlength="20" onblur="checkLength(this)" >
			                     </div>  
			                </div>
			                <div class="form-group" >
			                     <label class="col-sm-4 control-label">手机</label>
			                     <div class="col-sm-6">
			                        <input id="phone" type="text" class="form-control shareTitle"  onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'0')}else{this.value=this.value.replace(/\D/g,'')}" maxlength="11" >
			                     </div>  
			                </div>
			                <div class="form-group" >
			                     <label class="col-sm-4 control-label">需求描述</label>
			                     <div class="col-sm-6">
			                         <textarea id="requirementDescription" name="comment" class="form-control" placeholder="请输入文字" required="" aria-required="true" style="height:100px" maxlength="300" onblur="checkLength(this)"></textarea>                       
			                     </div>  
			                </div>
	                    </form>
	                </div>
                
                </div>
                <div class="modal-footer" style="text-align:center;border-top:none;">
                    <button type="button" class="btn btn-white" data-dismiss="modal" style="margin-top: 15px;">关闭</button>
                    <button type="button" class="btn btn-primary" style="margin-top: 15px;" onclick="javascript:customMadeMaterial();">保存</button>
                </div>
            </div>
        </div>
    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/gh/bootcdn/BootCDN/ajax/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="<%=path%>/hplus/js/plugins/iCheck/icheck.min.js"></script>
    <script type="text/javascript" src="<%=path%>/hplus/js/plugins/dataTables/jquery.dataTables.min.js"></script>
    <script src="<%=path%>/hplus/js/plugins/sweetalert/sweetalert2.min.js"></script>
    <script type="text/javascript" src="<%=path%>/js/marketing/dialog.js"></script>
	<script type="text/javascript" src="<%=path%>/js/marketing/public.js"></script>
	<script type="text/javascript" src="<%=path%>/js/marketing/lengthlimit.js"></script>
	<script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>
	<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
		<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.qrcode/1.0/jquery.qrcode.min.js"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/artDialog/7.0.0/dialog-plus.js"></script>
		<script type="text/javascript" src="<%=path%>/js/dateUtils.js"></script>
		<script type="text/javascript" src="<%=path%>/js/marketing/validation.js"></script>
    <script>
	    var path = "<%=path%>";
	    var myDataTable;
	    var materialName="";
	    var createUserId=0;
	    // 需要删除的id集合
	    var idList = new Array();
	    
	    var cid = "";
	    var lineNum = 0;
	    
	   	$.fn.dataTable.ext.errMode = 'none';
        $(function(){
        	init();
        });
        
        function init(){
        	myDataTable = dataTable();
        	
        }
        function func_dataTableReload(){
        	lineNum=0;
        	myDataTable.ajax.reload(function(){
        		$(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green"});
        		$('input').iCheck('uncheck');
        	});
        }
        function dataTable(){
        	return $('#mydataTable').DataTable({
        		processing: true,
        		ordering: false,
        		searching: false,
        		info: true,
        		autoWidth: true,
        		lengthChange: false,
        		"order": [[ 2, "desc" ]],
        	    language: {
        	    	emptyTable: '暂无数据',
        	    	info: '从第 _START_ 到第 _END_ 条数据；总共有 _TOTAL_ 条记录',
        			infoEmpty: '没有数据',
        			lengthMenu: '每页显示 _MENU_ 条记录',
        			loadingRecords: '正在加载数据....',
        			processing: '正在处理数据....',
        			zeroRecords: '没有找到匹配的记录',
        			paginate: {
        				first: '首页',
        				previous: '前页',
        				next: '后页',
        				last: '尾页'
        			}
        	    },
        	    order: [[1,'desc']],
        		pageLength: 20,
        	    pagingType: 'full_numbers',
        	    columnDefs: [{
        			render: function(data, type, full) {
        				var oTable = $('#mydataTable').dataTable();
        				var tableSetings=oTable.fnSettings();  
        				var paging_length=tableSetings._iDisplayLength;//当前每页显示多少  
        				var page_start=tableSetings._iDisplayStart;//当前页开始  
        				var page=(page_start / paging_length);
        				lineNum++;
        				return '<div class="checkbox i-checks" style="margin-left:8px;"><label class="is_checkd"><input class="childCheckbox" type="checkbox" id="'+full.id+'"></label> <span>'+(page*20+lineNum)+'</span></div>';
                    },
        			targets: 0
        		},{
        			render: function(data, type, full) {
        				return '<span title='+data+' style="vertical-align:middle;display:inline-block;width: 176px;overflow: hidden;word-break: keep-all;white-space: nowrap;text-overflow: ellipsis;">'+data+'</span>';
                    },
        			targets: 1
        		},{
        			render: function(data, type, full) {
        				if(data == 0){
        					return '<td id="statusText'+full.id+'">编辑</td>';
        				}else if(data == 3){
        					return '<td id="statusText'+full.id+'">停用</td>';
        				}else if(data == 4){
        					return '<td id="statusText'+full.id+'">未发布</td>';
        				}else{
        					if(full.useNum != 0){
        						return '<td id="statusText'+full.id+'">已使用</td>';
        					}else{
        						return '<td id="statusText'+full.id+'">未使用</td>';
        					}
        				}
                    },
        			targets: 2
        		},{
        			render: function(data, type, full) {
        				if(data == 0){
        					return "不限";
        				}else{
        					return  formatDateTimeYMD(full.startTime) + " 至 " +formatDateTimeYMD(full.endTime);
        				}
                    },
        			targets: 3
        		},{
        			render: function(data, type, full) {
        				cid = full.cid;
        				var status;
        				var result="";
        				if(full.status == 3){
        					result += '<shiro:hasPermission name="aem_material_list:enable"><a id="changeMaterialStatus'+data+'" materialId="'+data+'" status="3" class="caozuo updateStatus" >启用</a></shiro:hasPermission>';
        				}else if(full.status == 4){
        					result += '<shiro:hasPermission name="aem_material_list:enable"><a id="changeMaterialStatus'+data+'" materialId="'+data+'" status="4" class="caozuo publishMaterial" >发布</a></shiro:hasPermission>';
        				}else if(full.status == 0){
        					//编辑状态 发布按钮置灰
        					result += '<shiro:hasPermission name="aem_material_list:enable"><a class="caozuo" style="color:#ddd">发布</a></shiro:hasPermission>';
        				}else{
        					result += '<shiro:hasPermission name="aem_material_list:enable"><a id="changeMaterialStatus'+data+'" materialId="'+data+'" status="1" class="caozuo updateStatus" >停用</a></shiro:hasPermission>';
        				}
    					result += "<a id='showCode"+data+"' materialType='"+full.materialType+"' materialId='"+data+"'  class='caozuo showCode'>预览</a>";
    					result += '<shiro:hasPermission name="aem_material_list:edit"><a materialId="'+data+'"  class="caozuo editMaterial" materialId="'+data+'" materialType="'+full.materialType+'" href="javascript:;">编辑</a></shiro:hasPermission>';
    					result += '<shiro:hasPermission name="aem_material_list:copy"><a materialId="'+data+'"  class="caozuo copyMaterial" materialId="'+data+'" materialType="'+full.materialType+'" href="javascript:;">复制</a></shiro:hasPermission>';
    					
    					if(full.status == 0 || full.status == 3 || full.status == 4){
    						status = full.status;
        				}else{
        					if(full.useNum != 0){
        						status=2;
        					}else{
        						status=1;
        					}
        				}
    					if(full.useNum != 0 || full.status == 3){
    						result += '<shiro:hasPermission name="aem_material_list:delete"><a class="caozuo" style="color:#ddd">删除</a></shiro:hasPermission>';
    					}else{
    						result += '<shiro:hasPermission name="aem_material_list:delete"><a class="caozuo deleteMaterial" status="'+status+'" materialId="'+data+'" href="javascript:;">删除</a></shiro:hasPermission>';	
    					}
    					//判断是否为当天创建的素材
    					var diffDay = isToday(full.create_time);
    					//判断素材有效期是否开始
    					var startTimeDiff = dateDiff(new Date(),full.startTime);
    					if(diffDay || (full.validityType == 1 && startTimeDiff>0)){
    						result += '<shiro:hasPermission name="aem_material_list:count_mic"><a class="caozuo" style="color:#ddd">统计</a></shiro:hasPermission>';
    					}else{
    						result += '<shiro:hasPermission name="aem_material_list:count_mic"><a materialId="'+data+'"  class="caozuo" href="<%=path%>/material/materialCount?materialId='+data+'&materialName='+encodeURI(encodeURI(full.materialName))+'&isNeedCollect='+full.isNeedCollect+'">统计</a></shiro:hasPermission>';
    					}
    					return result;
                    },
        			targets: 4
        		}],
        	    columns: func_columns(), 
        	    serverSide: true,
        	    ajax: {
        	    	contentType: 'application/json;charset=utf-8',
        	    	type: 'POST',
        	    	url: func_AjaxUrl(),
        	    	data: function(d){
        	    		d.materialName=materialName;
        	    		d.createUserId=createUserId;
        				return JSON.stringify(d);
        			}
        		} , 
        	    "initComplete": function(settings, json) {
        	    	$(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",});
        	    }
        	}).on( 'draw', function () {
        		$(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",});
        	}).on( 'page.dt', function () {
        		    lineNum = 0;
        	});
        	
        }
        function func_AjaxUrl(){
        	return path+"/material/ajaxListMaterial";
        }
        /**
         *	设置列名，对应后台
         */
        function func_columns(){
        	var jsonArr = [
        		{"data":"id"},
        		{"data":"materialName"},
        		/* {"data":"uv"},
        		{"data":"shareUserCount"},
        		{"data":"sumitCount"}, */
        		{"data":"status"},
        		{"data":"validityType"},
        		{"data":"id"},
        	];
        	return jsonArr;
        }
        
        /* 输入框模糊搜索 */
        $("#createUser").autocomplete({
			source: function( request, response ) {
				$.post(path+"/material/ajaxUserListByLikeName",{name:request.term},function(data){
					if(data.status == "200"){
						response($.map(data.data,function(d){
							return {value:d.name,label:d.name,createUserId:d.id}
						}));
					}
				},"json");
			},
			select: function(e, u){
				createUserId = u.item.createUserId;
			}
		});
        
        /* 点击搜索按钮 */
        function search(){
        	materialName = $('#materialName').val();
        	if(!StringEmpty($('#createUser').val())){
        		createUserId = 0;
        	}
        	func_dataTableReload();
        }
        /* 批量删除 */
        function deleteByBatch(){
        	swal({
				  title: '删除确认',
				  text: "您确定要删除此H5素材吗?删除后将无法恢复，请谨慎操作！",
				  type: 'warning',
				  showCancelButton: true,
				  confirmButtonColor: '#1ab394',
				  cancelButtonColor: '#E8E8E8',
				  confirmButtonText: '确认',
				  cancelButtonText:'取消',
				  reverseButtons : true
				}).then(function () {
					var ids=idList.join(",");
		            if(!StringEmpty(ids)){
		                errorDialog("请选择要删除的素材!");
		            }else{
		                var url=path+"/material/ajaxDeleteBatchMaterial"
		                $.post(url, {
		                    "ids" : ids
		                }, function(data) {
		                    if (data.status == 200) {
		                        func_dataTableReload();
		                        successDialog("删除成功");
		                        idList.length=0;
		                    }else {
		                        errorDialog("删除失败",data.message);
		                    }
		                });
		            }
				})
        }
        /* 删除单个 */
         function deleteByOne(id){
        	swal({
				  title: '删除确认',
				  text: "您确定要删除此H5素材吗?删除后将无法恢复，请谨慎操作！",
				  type: 'warning',
				  showCancelButton: true,
				  confirmButtonColor: '#1ab394',
				  cancelButtonColor: '#E8E8E8',
				  confirmButtonText: '确认',
				  cancelButtonText:'取消',
				  reverseButtons : true
				}).then(function () {
					 var url=path+"/material/ajaxDeleteMaterial"
			            $.post(url, {
			                "id" : id
			            }, function(data) {
			                if (data.status == 200) {
			                    func_dataTableReload();
			                    successDialog("删除成功");
			                }else {
			                    errorDialog("删除失败",data.message);
			                }
			            });
				})
        }
        /* 停用启用 */
        function changeMaterialStatus(status,materialId){
        	var title = "";
        	var text = "";
        	var buttonText = "";
        	var statusText = "";
        	var changeStatus = 0;
        	var successText = "";
        	var failText;
        	if(status == 3){
        		title = "启用确认";
        		text = "您确定要启用此H5素材吗?";
        		buttonText = "停用";
        		statusText = "启用";
        		changeStatus=1;
        		successText = "启用成功";
        		failText = "启用失败";
        	}else{
        		title = "停用确认";
        		text = "您确定要停用此H5素材吗?停用后用户将无法进入素材页面！";
        		buttonText = "启用";
        		statusText = "停用";
        		changeStatus=3;
        		successText = "停用成功";
        		failText = "停用失败";
        	}
        	swal({
				  title: title,
				  text: text,
				  type: 'warning',
				  showCancelButton: true,
				  confirmButtonColor: '#1ab394',
				  cancelButtonColor: '#E8E8E8',
				  confirmButtonText: '确认',
				  cancelButtonText:'取消',
				  reverseButtons : true
				}).then(function () {
					 var url=path+"/material/ajaxUpdateMaterialStatus"
			            $.post(url, {
			                "id" : materialId,
			                "status" : changeStatus
			            }, function(data) {
			                if (data.status == 200) {
			                	$('#changeMaterialStatus'+materialId+'').html(buttonText);
			                	$('#changeMaterialStatus'+materialId+'').attr("status",changeStatus);
			                	func_dataTableReload();
			                    successDialog(successText);
			                }else {
			                    errorDialog(failText,data.message);
			                }
			            });
				})
        }
        /* 保存定制需求 */
        function customMadeMaterial(){
        	var name = $("#name").val();
        	var phone = $("#phone").val();
        	var requirementDescription = $("#requirementDescription").val();
        	if(StringEmpty(name) && StringEmpty(phone) && StringEmpty(requirementDescription)){
        		if(!validatemobile(phone)){
        			errorDialog("您输入的手机格式不正确，请重新输入！");
        			return ;
        		}
        		var url=path+"/material/ajaxSaveMaterialCustomize"
                $.post(url, {
                    "name" : name,
                    "phone" : name,
                    "requirementDescription" : requirementDescription
                }, function(data) {
                    if (data.status == 200) {
                    	$('#customMadeMaterial').modal('hide');
                        successDialog("提交成功");
                    }else {
                        errorDialog("提交失败");
                    }
                });
        	}else if(!StringEmpty(name)){
        		errorDialog("请输入姓名！");
        	}else if(!StringEmpty(phone)){
        		errorDialog("请输入手机！");
        	}else if(!StringEmpty(requirementDescription)){
        		errorDialog("请输入您的需求！");
        	}
        }
    </script>
    <!-- 点击事件 -->
    <script type="text/javascript">
       /* 启用停用 */
       $(document).on('click', '.updateStatus', function() {
    	  var status = $(this).attr("status");
    	  var materialId = $(this).attr("materialId");
    	  changeMaterialStatus(status,materialId); 
	   });
       /* 发布 */
       $(document).on('click', '.publishMaterial', function() {
     	  var materialId = $(this).attr("materialId");
     	  var url = "<%=path%>/material/ajaxPublishMaterial";
          $.post(url, {
        	"id":materialId,
          }, function (data) {
	            if (data.status == "200") {
	            	func_dataTableReload();
	            	successDialog("发布成功！");
	            } else {
	            	errorDialog("发布失败");
	            }
         });
 	   });
       
       /* 删除 */
       $(document).on('click', '.deleteMaterial', function() {
     	  var status = $(this).attr("status");
     	  var materialId = $(this).attr("materialId");
     	  if(status == 2 || status ==3){
     		  errorDialog("您选择的素材包含已使用素材，已使用素材不能删除！");
     		  return ;
     	  }
     	  deleteByOne(materialId);
 	   });
       
       
       /* 编辑 */
       $(document).on('click', '.editMaterial', function() {
     	  var materialType = $(this).attr("materialType");
     	  var materialId = $(this).attr("materialId");
     	 if(materialType == 1){
    		  window.location.href="<%=path%>/material/teletextMaterialCreate?handleType=edit&id="+materialId;
    	  }else{
    		  window.location.href="<%=path%>/material/photoAlbumMaterialCreate?handleType=edit&id="+materialId;
    	  }
 	   });
       
       /* 复制 */
       $(document).on('click', '.copyMaterial', function() {
     	  var materialType = $(this).attr("materialType");
     	  var materialId = $(this).attr("materialId");
     	 if(materialType == 1){
   		   window.location.href="<%=path%>/material/teletextMaterialCreate?handleType=copy&id="+materialId;
	   	 }else{
	   		  window.location.href="<%=path%>/material/photoAlbumMaterialCreate?handleType=copy&id="+materialId;
	   	 }
 	   });
    
        /* 全选 */
	    $('.select_all').on('ifChecked', function(event){
	    	$(".childCheckbox").attr("checked","checked"); 
			$(".childCheckbox").parent().addClass("checked");
			idList.length=0;
			$('.childCheckbox').each(function(i, d){
				var id=this.id;
				idList.push(id);
			});
	    });
        /* 取消全选 */
	    $('.select_all').on('ifUnchecked', function(event){
	    	$(".childCheckbox").removeAttr("checked","checked"); 
			$(".childCheckbox").parent().removeClass("checked");
			idList.length=0;
	    });
    
    
	    $(document).on('ifChecked', '.childCheckbox', function() {
	    	$(this).attr("checked","checked"); 
			$(this).parent().addClass("checked");
			var id=this.id;
			var checkCount=0;
			var totalCoun=0;
			$('.childCheckbox').each(function(i, d){
				totalCoun++;
			})
			$('.checked').each(function(i, d){
				checkCount++;
			})
			if(checkCount==totalCoun){
				$('.select_all').children().addClass("checked");
				$('.select_all').children().children().attr("checked","checked"); 
			}
			idList.push(id);
	    });
	    $(document).on('ifUnchecked', '.childCheckbox', function() {
	    	$(this).removeAttr("checked","checked"); 
			$(this).parent().removeClass("checked");
			var id=this.id;
			$('.select_all').children().removeClass("checked"); 
			$('.select_all').children().children().removeAttr("checked"); 
			idList.splice(contains(idList,id), 1);
	    });
	    
	    
	    $(document).on('click', '.showCode', function() {
	     	  var materialType = $(this).attr("materialType");
	     	  var materialId = $(this).attr("materialId");
		      var url="";
		      var path = window.parent.servicePath;
	     	  if(materialType == 1){
	     		 url = path+"/material/teletextMtaerialPreview?materialId="+materialId+"&cid="+cid;
		   	  }else{
		   		 url = path+"/material/photoAlbumMaterialPreview?materialId="+materialId+"&cid="+cid;	   	  
		   	  }
	     	  
	     	 var d = dialog({
					width: 175,
		 	        height:170,
		 	        padding:0,
		 	        align: 'top',
		 			content:"<div id='code'></div> <img src='' id='qrcodeImg' style='width:140px;height:140px;'/>"+
		 	        "<a id='download' download='qrcode.jpg'></a>"
		 	        ,
					quickClose: true// 点击空白处快速关闭
			 });
			 d.show(document.getElementById('showCode'+materialId));
			 
			 
			 var qrcode = $('#code').qrcode({
	    		   width: 110,
	    		   height:110,
	               text:url+""/*可以通过ajax请求动态设置*/
	        	 }).attr("style","display:none;");
	         	//将生成的二维码转换成图片格式
        	  var canvas = qrcode.find('canvas').get(0);
        	  $('#qrcodeImg').attr('src', canvas.toDataURL('image/jpg'));
        	  $(".ui-dialog").css("background-color" , "rgba(7, 17, 27, 0.3)"); 
	 	   });
	    /* function showQrcode(data){
			
	 		createQRCode("code",data,100,50,null);
		}
	    
	    //创建二维码
	    function createQRCode(id, data, w, h, src){
	    	$('#code').empty();
	    	var parse = parseUrl(window.location.href);  
    		var path = parse.protocol + '://' + parse.host + ':' + parse.port;
    		if("scrm_sps" == parse.segments[0]){
    			path +=  '/' + parse.segments[0];
    		}
    		
	    	var url=path+"/material/teletextMtaerialPreview?materialId="+data;
	    	 
		 
	    } */
    </script>
</body>
</html>
